home *** CD-ROM | disk | FTP | other *** search
/ Aminet 14 / Aminet 14 - Oct 1996.iso / TCalc / English / TurboCalc3.5Demo / Programmer / tclib.txt < prev   
Text File  |  1995-10-05  |  32KB  |  756 lines

  1. TurboCalc3 ©opyright 1993-94 by Michael Friedrich. All Rights Reserved
  2.  
  3. This document must not be copied, modified or released without my
  4. written permission. It is part of TurboCalc3.0.
  5.  
  6.  
  7. 1. TCLIB - TurboCalc Library
  8. ============================
  9.  
  10. Starting with version 3 of TurboCalc you have the possibility to enhance
  11. the internal functions, macros, objectclasses and other things by
  12. external routines. This way you, the user, can add personal features
  13. to TurboCalc to facilitate your work.
  14. This is done by providing external files with specific routines.
  15. The creation of such a file, called 'TCLib', will be discussed in the
  16. following text.
  17.  
  18. IMPORTANT: TO CREATE A TCLIB YOU SHOULD BE FAMILIAR WITH PROGRAMMING
  19.            THE AMIGA. FOR USING TURBOCALC IT IS NOT NECESSARY TO READ
  20.            OR UNDERSTAND THIS MANUAL.
  21.            Creating TCLibs is a very advanced feature of TurboCalc
  22.  
  23. Up to now, there are the following types of TCLibs:
  24.  
  25. * Filerequester
  26. * Objects
  27. * crypting-routines
  28. * External functions
  29. * External macro-commands
  30.  
  31.  
  32. 1.1. What is a TCLibs?
  33. ----------------------
  34.  
  35. A TCLib is an (almost) normal executable AmigaDOS-file and might thus be
  36. created with most of the popular compilers or assemblers.
  37.  
  38. Logically, each TCLib can be divided in three parts:
  39.  
  40. 1) The first part is the TCLib-header. It contains some useful information
  41.    about the TCLib and allows TurboCalc to verify that this is really
  42.    a TCLib. This prevents a system crash due to improper use.
  43.  
  44. 2) This header is finished with a list of all implemented routines, which
  45.    enables TurboCalc to find and call the 'real routines'.
  46.    (This part is often included in 1, and both are called header)
  47.  
  48. 3) Finally, the real routines are placed here.
  49.  
  50.  
  51. The header *must* be the first thing in your executable file. If you are
  52. using a compiler to create the TCLib you have to ensure that. To do this,
  53. all the startup-code must be removed. Further hints should be found in
  54. the description of 'creating libraries' in your compiler-documentation,
  55. as creating (normal) amigalibraries is much the same as creating TCLibs.
  56.  
  57.  
  58. Annotation: As the best way to implement such a TCLib is assembler and
  59. TurboCalc is completely written in assembler, all the structures and
  60. descriptions in this documentation will be in that language.
  61.  
  62. 2. TCLib-Structure
  63. ==================
  64.  
  65. 2.1. The Header
  66. ---------------
  67.  
  68.     The header looks like this:
  69.     In the first part, you will find some values that allow TurboCalc
  70.     to identify this TCLib and determine the type.
  71.  
  72.     The second part consists of a list of pointers for the respective
  73.     routines. The first four ones are common to all TCLib-types.
  74.     They are used on startup & when quitting TurboCalc. (See short
  75.     description in the structure below).
  76.  
  77.     The others are type-specific and will be explained in the
  78.     respective chapters below.
  79.  
  80.  
  81.  
  82.   STRUCTURE TCLib,0
  83.   LONG tclib_header   ; moveq #-13,d0     or $70F34E75
  84.                       ; rts
  85.                       ; if user tries to start this file!
  86.   LONG tclib_id       ; TCLIB_ID ('TCLB')
  87.   LONG tclib_subid    ; one of the TCLIB_SUBID's declared above
  88.   WORD tclib_version
  89.   WORD tclib_revision
  90.   LONG tclib_name     ; *text with short description of this lib
  91.   LONG tclib_ver      ; *ver_text
  92.   LONG tclib_author   ; *text with your name
  93.   LONG tclib_flags    ; reserved, set to 0.l for now
  94.   LONG lib_reserved1  ; dito
  95.   LONG lib_reserved2  ; dito
  96. ***** end of header part1
  97.  
  98.   LONG tclib_init     ;INIT: routine is called on startup, return one of:
  99.                       ;   0: if installed correctly
  100.                       ;   1: can't use: remove - try to load next time
  101.                       ;   -1: impossible to use: remove &  don't try
  102.                       ;       to load this lib again
  103.   LONG tclib_exit     ;END: routine is called before TurboCalc ends
  104.                       ;   free all allocated mem & other resources
  105.   LONG tclib_flush    ;FLUSH: routine is called when TurboCalc runs
  106.                       ; runs short of memory.
  107.                       ; lib is asked to free (temporarily) unused
  108.                       ;  memory (not used up to now, simply set to 0.l)
  109.  
  110.   LONG tclib_method   ; Global routine for all purposes, called with
  111.                       ; method (what shall be done?) and data.
  112.                       ; Isn't currently used. (Simply set to 0)
  113.  
  114.  
  115.   LABEL tclib_rout1   ; Here the type-specific routines start, they are
  116.                       ; defined in the type-specific description below.
  117.   LABEL TCLib_SIZEOF
  118.  
  119.  
  120.     The rest of this structure contains pointers to the used routines and
  121.     is thus depending on the type of TCLib.
  122.  
  123.  
  124.     Parameters are passed in registers (as usually in assembler),
  125.     see 'Calling Conventions' below.
  126.  
  127.  
  128.  
  129.  
  130. 2.2 FileRequester-TCLib
  131. -----------------------
  132.  
  133.     This TCLibs allows to change the TurboCalc-filerequester and
  134.     to replace it by a new one.
  135.  
  136.     You only need one routine asking for a filename. Thus the (rest of the)
  137.     TCLib-structure looks like this:
  138.  
  139.  
  140.   STRUCTURE TCLib_filereq,TCLib_SIZEOF
  141.   LONG libfr_filereq  ; open window & ask for filename
  142.           ; error=filereq(filename, title_text, screen, pattern, flags)
  143.           ;               a0        a1          a2      a3       d0
  144.           ; para: a0: *filename (200 chars reserved, both for old and
  145.           ;           for new filename, if returning d0=0)
  146.           ;       a1: *title_text
  147.           ;       a2: *screen (or 0.l for workbench)
  148.           ;       a3: *pattern
  149.           ;       d0: flags (bit0: save, bit1:drawer_only)
  150.           ;           (drawer_only isn't needed up to now!)
  151.           ; return: d0: 0=ok (filename is changed)
  152.           ;             1=abort
  153.           ;            -1=serious error (e.g. no mem)
  154.           ;               (in this case a simple string-
  155.           ;               filerequester will appear)
  156.   LABEL libfr_SIZEOF
  157.  
  158.  
  159. Annotation: In a0 your routines gets a pointer to a buffer with (at least)
  160. 200 chars containing the current filename. If the user selected a new
  161. filename and you're returning ok (d0=0), the buffer should be changed
  162. accordingly (i.e. the buffer should be filled with the new filename,
  163. complete path & name).
  164. All the other information might and should!) be used for better handling.
  165.  
  166.  
  167.  
  168.  
  169. 2.3 Crypt-TCLib
  170. ---------------
  171.  
  172. This TCLib is used to encrypt and decrypt the sheets when saving/loading
  173. and the respective option is set (in <Options-Protection>).
  174. Three routines are needed, one for setting the password and the other
  175. two for encryption & decryption.
  176.  
  177.  
  178.   STRUCTURE TCLib_crypt,TCLib_SIZEOF
  179.   LONG libcrypt_password  ; set password for en/decrypting
  180.           ; para: a0= *string, null-terminated
  181.           ;       either copy this string to your one buffer or
  182.           ;       (even better) use an algorithm to calculate
  183.           ;       real key (e.g. MD5 or CRC)
  184.   LONG libcrypt_encrypt   ; encrypt block
  185.           ; para: a0= *block
  186.           ;       d0= length of block (in bytes)
  187.   LONG libcrypt_decrypt   ; decrypt block
  188.           ; para: a0= *block
  189.           ;       d0= length of block (in bytes)
  190.   LABEL libcrypt_SIZEOF
  191.  
  192.  
  193. For every loading/saving the decryption/encryption-routines are called
  194. multiple times (once for each block). Block-size may vary (the first block
  195. is shorter (header missing) and the last block might be shorter as well)
  196. You should be prepared for this (e.g. by storing temporary data).
  197. You can rely on
  198.    i) libcrypt_password is called once directly before the en-/decryption.
  199.    ii) calls to _encrypt and _decrypt aren't mixed.
  200.    iii) buffer is longword-aligned (i.e. buffer&3=0)
  201.         and (except for the last block) length is a multiple of 4.
  202.         Thus it is possible to use (long)word commands.
  203.         (As the size of a TurboCalc-sheet isn't longword aligned, the
  204.         last block might have an odd size. Either you handle this or,
  205.         if you are lazy, you simple align the length to the next lower
  206.         (long)word-boundary, keeping the last three bytes unchanged.)
  207.  
  208.  
  209. For your information, loading works like this:
  210.     i) libcrypt_password is called to set the password
  211.     ii) first block is loaded in memory
  212.         and libcrypt_decrypt is called
  213.     iii) this is repeated until the complete file has been read.
  214.  
  215.  
  216.  
  217. 2.4. ObjectClass-TCLib
  218. ----------------------
  219.  
  220. This is the most complex TCLib (up to now). It is used to add new
  221. objectclasses allowing TurboCalc to handle and display various
  222. objects without an hardcoded limitation.
  223.  
  224. The TCLib-structure looks like this (first a short version without
  225. comments to give you a short overview - the full (documented) structure
  226. can be found below.
  227.  
  228.   STRUCTURE TCLib_objectclass,TCLib_SIZEOF
  229.   LONG liboc_nextclass
  230.   LONG liboc_classtext
  231.   LONG liboc_classid
  232.   BYTE liboc_flags0
  233.   BYTE liboc_flags1
  234.   BYTE liboc_flags2
  235.   BYTE liboc_flags3
  236.   LONG liboc_objectnew
  237.   LONG liboc_objectduplicate
  238.   LONG liboc_objectedit
  239.   LONG liboc_objectdraw
  240.   LONG liboc_objectload
  241.   LONG liboc_objectsave
  242.   LONG liboc_objectaction
  243.   LABEL liboc_SIZEOF
  244.  
  245.  
  246. With nextclass you can link different objectclasses. Thus you can
  247. put multiple objectclasses in one TCLib.
  248.  
  249. Classtext & classid describe the objectclass (the first for the use
  250. (in <Data-Create Object>) and the latter for saving or macro-commands).
  251.  
  252. Objectnew, objectduplicate and objectload are used for creating new
  253. instances of objects, objectedit allows the modification of this
  254. instance and objectsave stores this instance in a TurboCalc-sheet.
  255.  
  256. Objectdraw asks the objectclass to render the specific instance to
  257. a given rastport (in a specified size).
  258.  
  259.  
  260. Now the detailed structure:
  261.  
  262.  
  263.   STRUCTURE TCLib_objectclass,TCLib_SIZEOF
  264.   LONG liboc_nextclass
  265.           ; *next object-class (used by TC to keep list of all classes)
  266.           ; should be set to 0.l
  267.           ; (or to pointer on next object-class. This way you
  268.           ; can store multiple classes in one tclib! Last class
  269.           ; must have 0.l then!)
  270.   LONG liboc_classtext
  271.           ; *short_text (null-terminated), is object-description
  272.           ; This text will be shown in the <Data-Create Object>-Requester!
  273.   LONG liboc_classid
  274.           ; This field contains up to 4 chars with an id for this
  275.           ; objectclass (thus it should be unique). It is used to
  276.           ; select and define a specific objectclass (for loading/
  277.           ; saving or with the OBJECT-macro)
  278.           ; If the text has less then 4 chars, fill it with \0s
  279.           ; 'GEL\0', 'IFF\0', 'TEXT', 'CHRT' are used for the intern
  280.           ; object-classes, 'LOGO' for the extern one.
  281.           ; See MISSING.
  282.   BYTE liboc_flags0
  283. OBJCLASSFLAGS0_FRAME = 0    ; %00=off, %01=on, %10=3d, %11=3d-2
  284. OBJCLASSFLAGS0_FRAME_3d = 1
  285. OBJCLASSFLAGS0_BACKFILL = 2  ; enables backfill of object
  286. OBJCLASSFLAGS0_BACKWHITE = 3 ; backfill with white (instead of grey)
  287.   BYTE liboc_flags1
  288. OBJCLASSFLAGS1_EDITTASK = 0 ; call _objectedit from the task not the process
  289. OBJCLASSFLAGS1_ACTIONTASK = 1   ; dito for _objectaction (see tclib.doc)
  290.   BYTE liboc_flags2
  291.   BYTE liboc_flags3
  292.           ; object-flags, if not defined below: reserved & set to 0
  293.           ; liboc_flag0: default-values for new object:
  294.   LONG liboc_objectnew
  295.           ; object, flags = objectnew(num1/num2/*text)
  296.           ; d0      d1                  d0   d1   a0
  297.           ; generate a new, empty object
  298.           ; para: d0/d1/a0: number/number/*text
  299.           ;       Normally all three regs are set to 0.l, which asks
  300.           ;       for a default object.
  301.           ;       These paras are set by the macro-command OBJECT to
  302.           ;       allow the creation of a specific object.
  303.           ;
  304.           ;       if called with paras, see macro OBJECT
  305.           ;       otherwise all three regs are 0, it would be a good
  306.           ;           idea to return 1 in d1 (to let the user
  307.           ;           configurate his object - if needed)
  308.           ; return: d0: *object (or 0.l if not possible)
  309.           ;         d1: auto_edit (0=no, 1=call OBJECT_EDIT
  310.           ;             after initialization - if called with default
  311.           ;             paras 0/0/0 the a good idea to return d1=1
  312.           ;             (and thus let the user configurate this object,
  313.           ;             if possible)
  314.           ; ATTENTION: d0 is used by TC to identify the object
  315.           ; (of all classes), so d0 should be unique for all classes.
  316.           ; Thus return a pointer to allocated mem (either with
  317.           ; exec's or TC's routine!)
  318.   LONG liboc_objectduplicate
  319.           ; object = duplicate(object)
  320.           ; d0                 a0
  321.           ; Duplicate the object a0 return the new *object in d0
  322.           ; (or 0.l, if duplication failed)
  323.   LONG liboc_objectedit
  324.           ; redisplay = edit(object)
  325.           ; d0               a0
  326.           ; 'edit' the object a0 - e.g. open a requesterto user-change
  327.           ;                        object-settings
  328.           ; para: a0=*object (a3=*sheet, a4=*tcobject, both private!!!)
  329.           ; return: d0<>0: redisplay as something was changed!
  330.   LONG liboc_objectdraw
  331.           ; draw object a0
  332.           ; para: a0:*object
  333.           ;       a2: rp
  334.           ;       a6: *GfxBase (simply to make life easier ;^)
  335.           ;       d0-d3: object_box (x1/y1/x2/y2)
  336.           ;       d4: scale (for screen 0.l,
  337.           ;                  for printer: lower_word = numerator
  338.           ;                                upper_word = denominator
  339.           ;           'scale' is intended for scaling fonts
  340.           ;           you might prefer to use object_box for that reason
  341.           ;           (e.g. for scaling pictures)
  342.           ;           can be used to scale fonts...
  343.           ;               newsize=oldsize*(d4&0xffff)/(d4>>16)
  344.           ;           or in asm (d0=oldsize)
  345.           ;               tst.l   d4
  346.           ;               beq.s   noscale
  347.           ;               mulu    d4,d0
  348.           ;               swap    d4
  349.           ;               divu    d4,d0
  350.           ;               swap    d4
  351.           ;            noscale:
  352.           ;
  353.           ; d5: flags (currently unused: 0.l)
  354.   LONG liboc_objectload
  355.           ; Create new object by loading it from sheet.
  356.           ; This is a bit tricky...
  357.           ; para: d0=0 (or d0=1 & a0=*mem, see iii)
  358.           ; (a2=*tcobject, a3=*sheet, a4=*load_handle)
  359.           ;
  360.           ; return:
  361.           ;   a0: *object
  362.           ;   d0: flags
  363.           ; this allows the following tree possibilities:
  364.           ;   i) a0=*object, d0=0 (or d0=1, see iii)
  365.           ;  ii) a0=0.l, d0=0.l: error occured, no object created
  366.           ;                      (e.g. no memory)
  367.           ; iii) a0=0.l, d0=size
  368.           ;       When you return this, TurboCalc reads d0 bytes and
  369.           ;       calls this routine `loboc_objectload' again.
  370.           ;       Create your object from this memory then and
  371.           ;       return it in a0 (case i)
  372.           ;       If you return with a0=object & d0=0, TurboCalc frees
  373.           ;       the allocated memory for you (as TC allocated it)
  374.           ;       If you insist on freeing this piece of memory by your
  375.           ;       routine (e.g. it is exactly your private object-
  376.           ;       structure), then return with d0=1.
  377.           ;       (Remark: This mem is allocated with TC's AllocMemClear!
  378.           ;       your OBJECT_FREE-routine thus must free this mem
  379.           ;       with TC's FreeMem.)
  380.  
  381.   LONG liboc_objectsave
  382.           ; When TurboCalc saves a sheet (with objects) this routine
  383.           ; is called for every object.
  384.           ; para: a0 = object
  385.           ;       d0 = flags, normally 0 (or 1, see iv)!
  386.           ; (a2=*tcobject, a3=*sheet, a4=*save_handle)
  387.           ; return: a0 = *block
  388.           ;         d0 = blocksize
  389.           ;         d1 = flags
  390.           ;
  391.           ; You have the following four possibilities:
  392.           ;
  393.           ;   i) a0=*mem, d0=size, d1=0.l - don't free mem
  394.           ;       Save size bytes starting at mem, but to not free
  395.           ;       mem (usefull, if you simply return in a0 a pointer
  396.           ;       to your private structure - probably to be used
  397.           ;       with loading-case iii), d0=1 )
  398.           ;  ii) a0=*mem, d0=size, d1=1.l
  399.           ;       Save size bytes starting at mem, and free Mem via
  400.           ;       TurboCalc's FreeMem-Routine - this piece of memory
  401.           ;       thus should be allocated via AllocMem(Clear)
  402.           ; iii) a0=*mem, d0=size, d1=2.l - free mem via exec's
  403.           ;       Save size bytes starting at mem, and free Mem via
  404.           ;       exec's FreeMem-Routine: _LVOFreeMem(mem,size)
  405.           ; iv) a0=0.l, d0=size - return size only
  406.           ;       You want to save the object yourself using
  407.           ;       Write_Byte/Word/Long/Size (see below)
  408.           ;       To do this, TurboCalc calls this routine again
  409.           ;       (with para d0=1) after saving the object-header.
  410.           ;       Important: TurboCalc *must* save the object-header
  411.           ;       first, therefore the size must be specified correctly
  412.           ;               1) set a0=0 & d0=size, return (do *not* write
  413.           ;                  in this mode)
  414.           ;               2) your routine is called again with d0=1
  415.           ;                  Now write the size bytes with Write_...
  416.           ;                  and return: a0=0.l, d0=0.l
  417.   LONG liboc_objectaction
  418.           ; This routine is called when clicking on the object
  419.           ; para: d0=mode (0=click on object, 1=double-click)
  420.           ;       d1=flags (for clicking: 0=clicked on object (macro)
  421.           ;                               1=clicked on object (move)
  422.           ;                               2=clicked on 'size'
  423.           ;                               bit7: if set: object_back (for 1/2)
  424.           ;                (for double-click: is 0.l up to now)
  425.           ;       a0=object
  426.           ;
  427.           ; return: d0=error (0=ok)
  428.           ;         for double-click: if you return with d0<>0
  429.           ;               the default action (opening the settings-
  430.           ;               requester) isn't done, double-click will
  431.           ;               simple be aborted. This is usefull if you
  432.           ;               want to replace the default double-click-action.
  433.           ;         Return value is only used when OBJCLASSFLAGS1_ACTIONTASK
  434.           ;         is selected. Otherwise it is ignored (as the routine
  435.           ;         is called unsynchronously).
  436.           ;
  437.           ; Inportant: It is possible that (in future) new modes will be
  438.           ; added. So please check for the current (implemented) modes
  439.           ; and return d0=0 for the others (and do *not* rely on d0
  440.           ; being 1 if d0<>0!!!).
  441.           ;
  442.           ; You might do whatever you want (e.g. playing a sample
  443.           ; for moving/sizing, starting an external program on double-click)
  444.           ; IF your object has no 'special action' simply omit this
  445.           ; routine (by setting this pointer to 0.l)
  446.           ;
  447.   LABEL liboc_SIZEOF
  448.  
  449. Important: Some of these routines are called by TurboCalcs-Window task
  450. (which is used for the 'display'). Please note that it is not possible
  451. to call functions from the dos.library from a task (see dos.library for
  452. further information).
  453. These routines are called from the task:
  454. liboc_objectdraw (* see below)
  455. liboc_objectedit (**)
  456. liboc_objectaction (**)
  457.  
  458. If you need the dos.library from within these routines, you may
  459. start a new process doing your stuff. Attention: As the task does the
  460. complete window management your routine should be very short!
  461.  
  462. (*) liboc_objectdraw is called both from the task (for displaying
  463.     the object on screen) and from the process (for printing).
  464.     Thus the routine may be called twice (i.e. your routine
  465.     should be reentrant or at least be callable twice)
  466.  
  467.     These two modes can be distinguished with the help of register
  468.     d4 (scale) which is 0.l when called from the task and otherwise
  469.     reflects the scale (and is <>0.l in all cases).
  470.     Hint: This is useful for the following situation. If your objects
  471.     uses fonts they should be loaded on new/duplicate/load/edit so
  472.     the task can use them without using dos.library.
  473.     If the drawing routine is called then with d4<>0 (i.e. from the process
  474.     to render the object for printing) you can open a scaled and adapted
  475.     font, use it and close it again before returning from the drawing
  476.     routine.
  477.     Important: When called with d4=0 you *must not* use any function
  478.     with disk-access (i.e. most of the functions from dos.library
  479.     and OpenDiskFont from diskfont.library!)
  480.  
  481. (**) Those two routines are either called from the process or from
  482.      the task. You can control that behavior with the two flags
  483.      OBJCLASSFLAGS1_EDITTASK and OBJCLASSFLAGS1_ACTIONTASK defined above.
  484.      If you do not set them, your routines are called from the process
  485.      (asynchronously). This is the safer and easier way.
  486.      If your routines are only short (without disk-access) and related
  487.      to the actions very closely think of setting the respective flags
  488.      (e.g. only this way you can cancel a double-click or response
  489.      immediately to a mouse-click)
  490.  
  491.  
  492.  
  493. 2.5. External Functions/Macro-Commands
  494. --------------------------------------
  495.  
  496. This kind of TCLib is used to add external functions or macro-
  497. commands to TurboCalc. These new routines can be accessed via
  498. TCFUNCTION and TCMACRO respectively.
  499. You may mix functions and macros within one tclib, so you can
  500. provide one TCLib for one topic containing both functions and
  501. macros.
  502.  
  503.     STRUCTURE TCLib_function,TCLib_SIZEOF
  504.     LONG libfnc_flags   ; reserved, unused, set to 0.l!
  505.     LONG libfnc_count   ; #routines below (routine0..routinecount-1)
  506.     LONG libfnc_defaultroutine
  507.             ; this routine is called if either d7 >=count or
  508.             ; libfnc_routine(d7) is 0.l
  509.     LONG libfnc_routine0
  510. ;    LONG libfnc_routine1
  511. ;    LONG libfnc_routine2
  512. ;    ...
  513. ;    LONG libfnc_routine(count-1)
  514.     LABEL libfnc_SIZEOF
  515.  
  516. * parameters for all the fnc_routines:
  517.   d0-d1:  Value1 (as float)
  518.   d2:     Value1 (as long)
  519.   d3-d4:  Value2 (as float)
  520.   d5:     Value2 (as long)
  521.   d7:     routine-offset (0..) If libfnc_routinex is called, this
  522.            is equal to x and thus not needed. If libfnc_defaulroutine
  523.            is called you might need this data.
  524.   a0:     String (or 0.l) (must only be read not changed, will
  525.           be freed by TurboCalc when your routine returns!
  526.  
  527. Annotation: The two values are given both as float and as long.
  528. So you needn't convert them. 'Float' is the first one available
  529. in {mathieedoubbas/trans, mathieeesingbas/trans, mathffp/trans}
  530. (thus normally in double-ieee-format!).
  531.  
  532. * return (for functions):
  533.   d0/d1.l:  data (type dependent)
  534.   d2.l      type - one of:
  535.  
  536. TYPE_EMPTY = 0  ; no return value, shouldn't be used!
  537. TYPE_NO = 1     ; dito - please return NUM 0 instead (d0-d2 = 0/0/3)
  538. TYPE_FLOAT = 2  ; d0/d1.l is float as defined above
  539. TYPE_NUM = 3    ; d0.l is long
  540. TYPE_DATE = 4   ; d0.l is date (i.e. long)
  541. TYPE_TIME = 5   ; d0.l is date (i.e. long)
  542. TYPE_BOOL = 6   ; d0.l is bool (0=FALSE, 1=TRUE)
  543. TYPE_TEXT = 7   ; d0=*text (or 0, then is empty text!!!)
  544.                 ; texts *must* be allocted with AllocText, see
  545.                 ; calling conventions)
  546. TYPE_CELL = 8   ; d0.l=column/d1.l=row (you cannot return this in
  547.                 ; all situatuons)
  548. TYPE_ERROR = 9  ; d0.l=error (1..12)
  549.                 ;      with 1=don't know, 2=DIV/0, 3=VERSION
  550.                 ;      4=REFERENCE, 5=)-BRACKET, 6=TYPE, 7=NOCELL
  551.                 ;      8=ARG_NO_RANGE, 9=(-BRACKET, 10=SEMICOLON
  552.                 ;      11=VALUE, 12=EOLINE
  553.  
  554. * return (for macros):
  555.   d0.l:     error-code (0=ok, other see appendix of TurboCalc manual)
  556.  
  557. Hint: As you cannot determine if a macro-command is called as functions
  558. it is a good idea to return the error code together with d2=TYPE_NUM (3).
  559. When called as macro, d2 is ignored, otherwise it is interpreted
  560. as normal value.
  561.  
  562.  
  563.  
  564.  
  565.  
  566. 2.6. Calling Conventions
  567. ------------------------
  568. There are some important things about calling your routines from
  569. TurboCalc:
  570.  
  571. * All Parameters are passed in registers (as usually in assembler).
  572.   If you are using c, you need an assembler-routine pushing the
  573.   parameters on stack, calling your c-routine and popping them again
  574.   before returning.
  575.  
  576. * Return Value(s) are returned in registers as well (normally d0)
  577.  
  578. * You are free to change d0-d1/a0-a1 - all the other registers should
  579.   be preserved
  580.  
  581. * For C-Users (and other compiled languages): Either compile with
  582.   the option 'long code' (not using a base register) or set
  583.   this base register before entering your routine (e.g. get_a5)
  584.   Finally assure that the parameters are passed correctly (from
  585.   registers to stack), as mentioned above. Further hints could
  586.   probably be found in the chapter 'creating libraries' within
  587.   your compiler manual or RKM.
  588.  
  589. * You are passed in A5 a global data/routine-pointer from TurboCalc.
  590.   (for all routines). With that pointer you can access some useful
  591.   data (e.g. pointer on libraries) and some useful routines.
  592.  
  593.   Data is accessed via 'move.w offset(A5)' for example,
  594.   the routines may be called with 'jsr offset(A5)' or simply
  595.   XSR/XMP (defined in tclib2.i)
  596.  
  597.  
  598. TurboCalc_Version = -4      ; current revision/version
  599. TurboCalc_Revision = -2     ; of TurboCalc (starting with 3.02, sorry)
  600.   STRUCTURE MainData,0
  601.   LONG DosBase            ; Important: Dos, Gfx & Intuitionbase will
  602.   LONG GfxBase            ; be set correctly (as TC needs them to work),
  603.   LONG IntuitionBase      ; but you can't rely on the other libbases.
  604.   LONG LayersBase         ; They may be zero, if these libs aren't
  605.   LONG DiskFontBase       ; currently available in the system (e.g.
  606.   LONG WBBase             ; workbench is closed or KS 1.3 for asl.library)
  607.   LONG ASLBase
  608.   LONG IFFParseBase
  609.   LONG RexxBase
  610.   LONG AmigaGuideBase
  611.   LONG LocaleBase
  612. *
  613.   LONG FirstWindow        ; private
  614.   LONG FirstSheet         ;  .  not even think of touching them!!!
  615.   LONG FirstFont          ;  .
  616.   LONG FontList           ;  .
  617.   LONG LocaleCatalog      ;  .
  618.   LONG AmigaGuideHandle   ;  .
  619.   LONG Screen             ; private
  620. *
  621.   LONG Com_DiskErrorAdr   ; error-routine-adr for Read_ & Write_ see below!
  622.  
  623. * some useful routines
  624. * each vector consits of 6 bytes (first two: jmp, then the address)
  625. * call them as you normally call libraries (see macros XSR & XMP above)
  626. * if not mentioned otherwise, only d0-d1/a0-a1 are changed!
  627. *
  628.   XVECT AllocMem          ; para: d0 = size, return d0=a0=*mem - flags set
  629.                           ; size is stored by TC & this piece of memory
  630.                           ; will be freed automatically by TC
  631.                           ; (when TC ends and it hasn't been freed yet)
  632.   XVECT AllocMemClear     ; dito, but memory is cleared
  633.   XVECT FreeMem           ; para: a0 = *mem, frees with AllocMem allocated
  634.                           ; memory. Size was stored by AllocMem
  635.   XVECT DuplicateA0       ; para: a0 =*string (0-terminated mem)
  636.                           ; return: a0=*new piece of mem with the same text
  637.                           ; (allocated with AllocMem)
  638.                           ; changed: only a0 is changed!
  639. * the next tree memory-routines are used for storing small pieces of memory
  640. * they are used for cell-texts, function-texts, cell-information,...
  641.   XVECT AllocTEXTMem      ; para: d0.l = size, return d0=a0=*mem
  642.   XVECT FreeTextMem       ; para: a0.l = allocated mem (with AllocTEXTMem!)
  643.   XVECT DuplicateTEXT     ; para: a0= *string (0-terminated)
  644.                           ; return: a0=*mem (allocated with AllocTEXTMem)
  645. *
  646.   XVECT GetTexta0         ; private
  647.   XVECT GetTexta1         ; private
  648.   XVECT GetTexta2         ; private
  649.   XVECT UpperCaseD0       ; d0.b  = UpperCase(d0.b)
  650. *
  651.   XVECT DOS_SendMessage_stack         ; private
  652.   XVECT IDCMP_SendMessage_stack       ; .
  653.   XVECT CheckA4_Sheet_getsheet        ; .  do not use these routines!!!
  654.   XVECT CheckA4_Diagram               ; .
  655.   XVECT CheckA3                       ; .
  656.   XVECT StartClip                     ; .
  657.   XVECT EndClip                       ; .
  658.   XVECT SetClip                       ; private
  659. *
  660.   XVECT Call_CDX      ; d0/d1=float1, d3/d4=float2, d7=cmd
  661.                       ; for cmd see list below!
  662. * 'get information'-routines (column/row start at 0 for first one!)
  663. * all these routines need parameter a3=*sheet!
  664.   XVECT Column_GetEntry   ; para: d0=column, return: a0=*column or 0.l
  665.   XVECT Column_GetEntry_readonly  ; dito, but no creation
  666.   XVECT Row_GetEntry      ; para: d0=row, return: a0=*row or 0.l
  667.   XVECT Row_GetEntry_readonly     ; dito, but no creation
  668.   XVECT Cell_GetEntry     ; para: d0/d1=column/row, return: a0=*cell or 0.l
  669.   XVECT Cell_GetEntry_readonly    ; dito, but no creation
  670.   XVECT Cell_GetInt       ; para: d0/d1=column/row
  671.                           ; return: d0=int, d2=TYPE_NUM(3.l) or d2=0 (error)
  672.   XVECT Cell_GetFloat     ; para: d0/d1=column/row
  673.                           ; return: d0/d1=float, d2=TYPE_FLOAT(2.l) or d2=0 (error)
  674.   XVECT Cell_GetText      ; para: d0/d1=column/row
  675.                           ; return: a0=*text (allocated with AllocMemClear)
  676.                           ; or 0.l for error!
  677.                           ; (everything will be converted to text!!!)
  678. * loading/saving-routines.
  679. *_Open-Routines change a4 as a private file-handle (containing a buffer,...)
  680. * All other routines need this handle in a4
  681. * Error handling: Except for _Open (and close, where no error can occur)
  682. * the reading/writing routines jump to the adress 'DiskErrorAdr', if
  683. * an error occurs. If you have stored the current stackpointer (a7)
  684. * when calling _Open, you can set it and close the file.
  685. * ..._Byte/Word/Long only change register d0, d1-d7/a0-a6 aren't touched!
  686.   XVECT Read_Open_noerror ; d0=0:ok, else error - a4=handle (is returned)
  687.   XVECT Read_Close    ; close file a4
  688.   XVECT Read_Byte     ; d0.b = read byte from file a4
  689.   XVECT Read_Word     ; d0.w
  690.   XVECT Read_Long     ; d0.l
  691.   XVECT Read_Size     ; read d0.l bytes to a0.l from file a4
  692.   XVECT Read_TestEOF  ; d0=0: eof, else not
  693. *
  694.   XVECT Write_Open    ; d0=0:ok, else error - a4=handle (is returned)
  695.   XVECT Write_Close   ; close file a4
  696.   XVECT Write_Byte    ; write byte d0.b to file a4
  697.   XVECT Write_Word    ; write word d0.w to file a4
  698.   XVECT Write_Long    ; write long d0.l to file a4
  699.   XVECT Write_Size    ; write d0.l bytes from a0.l to file a4
  700. * drawing routines, for all: a2=rp, a6=gfxbase (has to be set!)
  701.   XVECT XSetAPen   ; d0=color
  702.   XVECT XSetAPen_color ; d0=color
  703.   XVECT XSetBPen   ;  d0=color
  704.   XVECT XSetBPen_color ; d0=color
  705.   XVECT XDrawLine ; d0-d3=x1/y1/x2/y2
  706.  
  707.  
  708.  
  709.  
  710. 3. Writing an own TCLib
  711. ========================
  712.  
  713. With this document and a bit programming experience it should
  714. be possible for you to write you own routines.
  715.  
  716.  
  717. 3.1 Examples
  718. ------------
  719.  
  720. There are two examples included to show how to create own TCLibs.
  721. Both examples are in assembler only (sorry), but feel free to
  722. make new examples in your favorite language (and send it to me
  723. to enlarge the examples, if you like to).
  724. The examples have been archived to 'Examples.Lha' due to lack of
  725. disk storage.
  726.  
  727.  
  728.  
  729. 3.2 Problems & Suggestions
  730. --------------------------
  731.  
  732. If you have problems are some suggestions when writing your TCLib
  733. that can't be solved by this document and you have an email account
  734. you are free to contact me:
  735.  
  736. s_friedr@ira.uka.de
  737. ukrc@rz.uni-karlsruhe.de
  738.  
  739. But:
  740. * Read this document first, as this might already help you
  741. * I try to reply to all emails, but i can't guarantee that :)
  742.  
  743.  
  744. 3.3. New TCLib
  745. --------------
  746.  
  747. After you finished your TCLib. it would be very nice to send me a copy
  748. of your TCLib. First of all, I'm really interested whether there is some-
  749. one writing TCLibs and what kind of routines he's implementing.
  750. And then, if you agree, your TCLibs can be put onto the disk of the
  751. next version or be posted in some nets.
  752. In all cases, I will respect your copyright, so please note, whether your
  753. TCLib is in Public Domain (and I'm allowed/not allowed to put it on
  754. the TurboCalc-Disk) or if this is only a private copy for myself.
  755.  
  756.